package com.owulia.leetcode.num.stack;

class MinStackAns {

    int[] array = new int[10];
    int[] minArray = new int[11];
    int index = -1;

    public MinStackAns() {
        minArray[0] = Integer.MAX_VALUE;
    }

    public void push(int val) {
        index++;
        if (index >= array.length) {
            int[] newArray = new int[array.length * 2 + 10];
            System.arraycopy(array, 0, newArray, 0, index);
            array = newArray;
            int[] newMinArray = new int[array.length + 1];
            System.arraycopy(minArray, 0, newMinArray, 0, index + 1);
            minArray = newMinArray;
        }
        array[index] = val;
        minArray[index + 1] = Math.min(minArray[index], val);
    }

    public void pop() {
        index--;
    }

    public int top() {
        return array[index];
    }

    public int getMin() {
        return minArray[index + 1];
    }
}